package com.itheima.socketTcp01;

import com.sun.scenario.animation.shared.ClipEnvelope;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerTcp {
    public static void main(String[] args) throws IOException {
//1、创建服务器端Socket对象ServerSocket，指定接收数据的端口号
        ServerSocket ss = new ServerSocket(10083);
//2、监听客户端连接，返回一个对应的Socket对象
        Socket accept = ss.accept();

//3、根据Socket对象获取输入流来读取数据，同理，为一行行读取，包装成缓冲字符输入流
        BufferedReader br= new BufferedReader(
                new InputStreamReader(
                        accept.getInputStream()));


        String ip=accept.getInetAddress().getHostAddress();
        String len;
        while ((len=br.readLine())!=null){
            System.out.println(ip + "说：" + len);

        }
        ss.close();

    }
}
